package app.sceledroid.network;

import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;

import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;

import android.app.ProgressDialog;
import android.content.Context;
import android.os.AsyncTask;
import android.util.Log;
import app.sceledroid.entity.Course;
import app.sceledroid.entity.User;
import app.sceledroid.services.SceleService;

public class CourseItemsGrabber extends AsyncTask<Course, Void, Document> {

	private Context context;
	private DefaultHttpClient client;
	private ProgressDialog dialog;
	private SceleService sceleService;

	public CourseItemsGrabber(Context context, DefaultHttpClient client,
			SceleService sceleService) {
		super();
		this.context = context;
		this.client = client;
		this.sceleService = sceleService;
	}

	@Override
	protected void onPostExecute(Document result) {
		// TODO Auto-generated method stub
		super.onPostExecute(result);
	}

	@Override
	protected void onPreExecute() {
		// TODO Auto-generated method stub
		super.onPreExecute();
	}

	@Override
	protected void onProgressUpdate(Void... values) {
		// TODO Auto-generated method stub
		super.onProgressUpdate(values);
	}

	@Override
	protected Document doInBackground(Course... courses) {
		// TODO Auto-generated method stub
		try {
			Course c = courses[0];
			HttpGet request = new HttpGet(c.getUrl());
			HttpResponse response = client.execute(request);
			InputStream stream = response.getEntity().getContent();
			
			Document doc = Jsoup.parse(stream, "UTF-8", c.getUrl());
			Log.v("Document", doc.text());
			return doc;
			
		} catch (ClientProtocolException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		return null;
	}

}
